﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WS.EKA.Business.Model;
using WS.EKA.Business.Utilty;
using System.Data;
using Oracle.DataAccess.Client;

namespace WS.EKA.Business.Dal
{
    public class ApplicationAccess
    {
        static IDB db = DBFactory.CreateBODB();

        public static List<TB_Application> GetApplication()
        {
            DataTable table = db.ExecuteDataTable("select app_code,app_name,app_type,isactive,comments,to_char(update_date,'yyyy-mm-dd HH24:mi:ss') as update_date from tb_application order by app_code");
            return table.ToList<TB_Application>();
        }

        public static void Update(TB_Application app)
        {
            var parameters = new List<OracleParameter>();
            parameters.Add(new OracleParameter("app_name", app.APP_NAME));
            parameters.Add(new OracleParameter("app_type", app.APP_TYPE));
            parameters.Add(new OracleParameter("isactive", app.IsActive));
            parameters.Add(new OracleParameter("comments", app.COMMENTS));
            parameters.Add(new OracleParameter("app_code", app.APP_CODE));
            string sql = @"update tb_application set app_name=:app_name,app_type=:app_type,isactive=:isactive,comments=:comments,update_date=sysdate where app_code=:app_code";
            db.ExecuteNonQuery(sql, parameters.ToArray());
        }

        public static void Insert(TB_Application app)
        {
            var parameters = new List<OracleParameter>();
            parameters.Add(new OracleParameter("app_code", app.APP_CODE));
            parameters.Add(new OracleParameter("app_name", app.APP_NAME));
            parameters.Add(new OracleParameter("app_type", app.APP_TYPE));
            parameters.Add(new OracleParameter("isactive", app.IsActive));

            string sql = @"insert into tb_application(app_code,app_name,app_type,update_date,isactive) values(:app_code,:app_name,:app_type,sysdate,:isactive)";
            db.ExecuteNonQuery(sql, parameters.ToArray());
        }
    }
}
